<?php
 

define('IN_SCRIPT',1);

/* Get all the required files and functions */
require_once('hd_settings.inc.php');
require_once('language/'.$hd_settings['language'].'.inc.php');
require_once('inc/common.inc.php');

/* Connect to database */
require_once('inc/database.inc.php');
hd_dbConnect();

hd_session_start();
hd_isLoggedIn();
/* Must be administrator to access this page */
hd_isAdmin();

$enable_save_settings=0;
$enable_use_attachments=0;

/* Print header */
require_once('inc/header.inc.php');

/* Print main manage users page */
require_once('inc/show_admin_nav.inc.php');
?>

</td>
</tr>
<tr>
<td>

<h3 align="center"><?php echo $hdlang['settings']; ?></h3>

<p><?php echo $hdlang['settings_intro'] . ' <b>' . $hdlang['all_req']; ?></b></p>

<script language="javascript" type="text/javascript"><!--
function hd_checkFields() {
d=document.form1;
if (d.s_site_title.value=='') {alert('<?php echo $hdlang['err_sname']; ?>'); return false;}
if (d.s_site_url.value=='') {alert('<?php echo $hdlang['err_surl']; ?>'); return false;}

if (d.s_support_mail.value=='' || d.s_support_mail.value.indexOf(".") == -1 || d.s_support_mail.value.indexOf("@") == -1)
{alert('<?php echo $hdlang['err_supmail']; ?>'); return false;}
if (d.s_webmaster_mail.value=='' || d.s_webmaster_mail.value.indexOf(".") == -1 || d.s_webmaster_mail.value.indexOf("@") == -1)
{alert('<?php echo $hdlang['err_wmmail']; ?>'); return false;}
if (d.s_noreply_mail.value=='' || d.s_noreply_mail.value.indexOf(".") == -1 || d.s_noreply_mail.value.indexOf("@") == -1)
{alert('<?php echo $hdlang['err_nomail']; ?>'); return false;}

if (d.s_hd_title.value=='') {alert('<?php echo $hdlang['err_htitle']; ?>'); return false;}
if (d.s_hd_url.value=='') {alert('<?php echo $hdlang['err_hurl']; ?>'); return false;}
if (d.s_server_path.value=='') {alert('<?php echo $hdlang['err_spath']; ?>'); return false;}
if (d.s_max_listings.value=='') {alert('<?php echo $hdlang['err_max']; ?>'); return false;}
if (d.s_print_font_size.value=='') {alert('<?php echo $hdlang['err_psize']; ?>'); return false;}

if (d.s_database_host.value=='') {alert('<?php echo $hdlang['err_dbhost']; ?>'); return false;}
if (d.s_database_name.value=='') {alert('<?php echo $hdlang['err_dbname']; ?>'); return false;}
if (d.s_database_user.value=='') {alert('<?php echo $hdlang['err_dbuser']; ?>'); return false;}
if (d.s_database_pass.value=='') {alert('<?php echo $hdlang['err_dbpass']; ?>'); return false;}

if (d.s_use_custom[1].checked) {
    if (d.s_custom1_use.checked && d.s_custom1_name.value == '') {alert('<?php echo $hdlang['err_custname']; ?>'); return false;}
    if (d.s_custom2_use.checked && d.s_custom2_name.value == '') {alert('<?php echo $hdlang['err_custname']; ?>'); return false;}
    if (d.s_custom3_use.checked && d.s_custom3_name.value == '') {alert('<?php echo $hdlang['err_custname']; ?>'); return false;}
    if (d.s_custom4_use.checked && d.s_custom4_name.value == '') {alert('<?php echo $hdlang['err_custname']; ?>'); return false;}
    if (d.s_custom5_use.checked && d.s_custom5_name.value == '') {alert('<?php echo $hdlang['err_custname']; ?>'); return false;}
}

return true;
}
//-->
</script>

<form method="POST" action="admin_settings_save.php" name="form1" onSubmit="return hd_checkFields()">

<table border="0" cellspacing="0" cellpadding="5" size="750">
<tr>
<td>

<!-- Check file and folder permissions -->
<table border="0">
<tr>
<td width="750"><?php echo $hdlang['check_status']; ?></tr>
</table>
<table border="0">
<tr>
<td align="left" width="200" valign="top"><b>/hd_settings.inc.php</b></td>
<td align="left" width="550">
<?php
if (is_writable('hd_settings.inc.php')) {
    $enable_save_settings=1;
    echo '<font class="success">'.$hdlang['exists'].'</font>, <font class="success">'.$hdlang['writable'].'</font>';
} else {
    echo '<font class="success">'.$hdlang['exists'].'</font>, <font class="error">'.$hdlang['not_writable'].'</font><br>'.$hdlang['e_settings'];
}
?>
</td>
</tr>

</table>

<hr width="750">

<!-- Website info -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['wbst_title']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_site_title" size="40" maxlength="255" value="<?php echo $hd_settings['site_title']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['wbst_url']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_site_url" size="40" maxlength="255" value="<?php echo $hd_settings['site_url']; ?>"></td>
</tr>
</table>

<hr width="750">

<!-- E-mails -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['email_sup']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_support_mail" size="40" maxlength="255" value="<?php echo $hd_settings['support_mail']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['email_wm']; ?>: </td>
<td align="left" width="550"><input type="text" name="s_webmaster_mail" size="40" maxlength="255" value="<?php echo $hd_settings['webmaster_mail']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['email_noreply']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_noreply_mail" size="40" maxlength="255" value="<?php echo $hd_settings['noreply_mail']; ?>"></td>
</tr>
</table>

<hr width="750">

<!-- Helpdesk settings -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['hd_title']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_hd_title" size="40" maxlength="255" value="<?php echo $hd_settings['hd_title']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['hd_url']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_hd_url" size="40" maxlength="255" value="<?php echo $hd_settings['hd_url']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['hd_path']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_server_path" size="40" maxlength="255" value="<?php
if ($hd_settings['server_path'] == '/home/mysite/public_html/hd') {
    echo getcwd();
} else {
    echo $hd_settings['server_path'];
}
?>">
</td>
</tr>
 <tr>
<td align="right" width="200"><?php echo $hdlang['hd_lang']; ?>:</td>
<td align="left" width="550">
<select name="s_language">
<?php
$dir = getcwd().'/language';
$path = opendir($dir);
$files = array();

while (false !== ($file = readdir($path))) {
    if(is_file($dir.'/'.$file) && substr($file, -8) == '.inc.php') {
        $files[]=$file;
    }
}

if(!empty($files)) {
    natcasesort($files);
    foreach ($files as $file) {
        $file=substr($file, 0, -8);
        if ($file == $hd_settings['language']) {
            echo '<option value="'.$file.'" selected>'.ucfirst($file).'</option>';
        } else {
            echo '<option value="'.$file.'">'.ucfirst($file).'</option>';
        }
    }
}

closedir($path);
?>
</select>
</td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['max_listings']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_max_listings" size="5" maxlength="3" value="<?php echo $hd_settings['max_listings']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['print_size']; ?>: </td>
<td align="left" width="550"><input type="text" name="s_print_font_size" size="5" maxlength="3" value="<?php echo $hd_settings['print_font_size']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['debug_mode']; ?>: </td>
<td align="left" width="550">
<?php
    $on = $hd_settings['debug_mode'] ? 'checked' : '';
    $off = $hd_settings['debug_mode'] ? '' : 'checked';
    echo '
    <label><input type="radio" name="s_debug_mode" value="0" '.$off.'> '.$hdlang['off'].'</label> |
    <label><input type="radio" name="s_debug_mode" value="1" '.$on.'> '.$hdlang['on'].'</label>';
?>
</td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['use_secimg']; ?>: </td>
<td align="left" width="550">
<?php
if(function_exists('imagecreate')) {
    $on = $hd_settings['secimg_use'] ? 'checked' : '';
    $off = $hd_settings['secimg_use'] ? '' : 'checked';
    echo '
    <label><input type="radio" name="s_secimg_use" value="0" '.$off.'> '.$hdlang['off'].'</label> |
    <label><input type="radio" name="s_secimg_use" value="1" '.$on.'> '.$hdlang['on'].'</label>';
}
else {
    echo $hdlang['secimg_no'];
}
?>
</td>
</tr>
</table>

<hr width="750">

<!-- Database settings -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['db_host']; ?>: </td>
<td align="left" width="550"><input type="text" name="s_database_host" size="30" maxlength="255" value="<?php echo $hd_settings['database_host']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['db_name']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_database_name" size="30" maxlength="255" value="<?php echo $hd_settings['database_name']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['db_user']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_database_user" size="30" maxlength="255" value="<?php echo $hd_settings['database_user']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['db_pass']; ?>:  </td>
<td align="left" width="550"><input type="text" name="s_database_pass" size="30" maxlength="255" value="<?php echo $hd_settings['database_pass']; ?>"></td>
</tr>
</table>

<hr width="750">


<!-- Custom fields -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['custom_use']; $onload_status=''; ?>: </td>
<td align="left" width="550"><label><input type="radio" name="s_use_custom" value="0" <?php if(!$hd_settings['use_custom']) {echo ' checked '; $onload_status=' disabled ';} ?>
onClick="hd_attach_disable(new Array('cpos1','cpos2','c11','c12','c13','c14','c21','c22','c23','c24','c31','c32','c33','c34','c41','c42','c43','c44','c51','c52','c53','c54'))">
<?php echo $hdlang['no']; ?></label> |
<label><input type="radio" name="s_use_custom" value="1" onClick="hd_attach_enable(new Array('cpos1','cpos2','c11','c21','c31','c41','c51'))" <?php if($hd_settings['use_custom']) {echo ' checked ';} ?>>
<?php echo $hdlang['yes']; ?></label></td>
</tr>

<tr>
<td align="right" width="200"><?php echo $hdlang['custom_place']; ?>: </td>
<td align="left" width="550">
<label><input type="radio" name="s_custom_place" id="cpos1" value="0" <?php if($hd_settings['custom_place']==0) {echo ' checked ';} echo $onload_status; ?>>
<?php echo $hdlang['place_after']; ?></label> |
<label><input type="radio" name="s_custom_place" id="cpos2" value="1" <?php if($hd_settings['custom_place']==1) {echo ' checked ';} echo $onload_status; ?>>
<?php echo $hdlang['place_before'];?></label>
</td>
</tr>

<?php
for ($i=1;$i<=3;$i++) {
    $this_field='custom' . $i;

    if ($onload_status==' disabled ') {
        $onload_locally=' disabled ';
    } elseif ($hd_settings['custom_fields'][$this_field]['use']) {
        $onload_locally='';
    } else {
        $onload_locally=' disabled ';
    }

    if ($i==2 || $i==4) {
        $color='';
    } else {
        $color=' class="white" ';
    }

echo '
<tr>
<td align="right" width="200" valign="top" '.$color.'>'.$hdlang['custom_f'].' '.$i.':   </td>
<td align="left" width="550" '.$color.'>
        <label><input type="checkbox" name="s_custom'.$i.'_use" value="1" id="c'.$i.'1" '; if ($hd_settings['custom_fields'][$this_field]['use']) {echo 'checked';} echo $onload_status.' onClick="hd_attach_toggle(\'c'.$i.'1\',new Array(\'c'.$i.'2\',\'c'.$i.'3\',\'c'.$i.'4\'))"> '.$hdlang['custom_u'].'</label><br>
        <label><input type="checkbox" name="s_custom'.$i.'_req" value="1" id="c'.$i.'2" '; if ($hd_settings['custom_fields'][$this_field]['req']) {echo 'checked';} echo $onload_locally.'> '.$hdlang['custom_r'].'</label><br>
        '.$hdlang['custom_n'].': <input type="text" name="s_custom'.$i.'_name" size="30" maxlength="255" id="c'.$i.'3" value="'.$hd_settings['custom_fields'][$this_field]['name'].'"'.$onload_locally.'><br>
        '.$hdlang['custom_l'].': <input type="text" name="s_custom'.$i.'_maxlen" size="5" maxlength="5" id="c'.$i.'4" value="'.$hd_settings['custom_fields'][$this_field]['maxlen'].'"'.$onload_locally.'><br>
</td>
</tr>
';
} // End FOR
?>

</table>

<p>&nbsp;</p>

<p align="center">
<?php
if ($enable_save_settings) {
    echo '<input type="submit" value="'.$hdlang['save_changes'].'" class="button">';
} else {
    echo '<input type="submit" value="'.$hdlang['save_changes'].' ('.$hdlang['disabled'].')" class="button" disabled><br><font class="error">'.$hdlang['e_save_settings'].'</font>';
}
?></p>

</form>

</td>
</tr>
</table>
</center>
</div>

<?php
require_once('inc/footer.inc.php');
exit();
?>
